<div id="manage-chapters">

  <h4><%=h t('.delete_reorder', :default => "Delete/reorder chapters") %></h4>

  <p id="drag" style="display: none;"><%=h t('.drag', :default => "Drag chapters to change their order.") %><p> 
  <%= update_page_tag do |page| page.toggle "drag" end %>  
  <noscript><p><%=h t('.enter', :default => "Enter new chapter numbers.") %><p></noscript>

  <%= form_tag url_for(:action => 'update_positions') do %>
  <ul id="sortable_chapter_list">
    <% for chapter in @chapters %>
      <li id="chapter_<%= chapter.id %>" class='chapter-position-list'>
        <%= text_field_tag 'chapters[]', nil, :size => 3, :maxlength => 3, :class => 'chapter-position-field', :id => 'chapters_' + chapter.position.to_s %>
        <span id='position-for-<%= chapter.id %>'><%= chapter.position %></span>. 
        <%= chapter.chapter_title %>
        <ul class='chapter-control navigation'>
          <li><%= link_to t('.edit', :default => 'Edit'), [:edit, @work, chapter] %></li>
           <% if @work.chapters.count > 1 %>
             <li><%= link_to t('.delete', :default => 'Delete'), [@work, chapter], :confirm => t('.links.are_you_sure', :default => 'Are you sure?'), :method => :delete %></li>
             <% if @work.pseuds.size > 1 && chapter.pseuds.size > 1 %>
               <li><%= link_to t('.remove_me', :default => "Remove Me As Author"), {:action => "edit", :id => chapter.id, :remove => "me"}, :confirm => t('.confirm_removal', :default => 'You will no longer be able to edit this chapter. Are you sure?') %></li>
             <% end %> 
          <% end %>
      	</ul>
      </li>
    <% end %>    
  </ul>
  <p class="submit"><%= submit_tag t('.update', :default => "Update Positions") %></p>
  <% end %>
</div>

<%= sortable_element('sortable_chapter_list', :url => {:action => :update_positions}) %>
